package com.bonc.rms.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bonc.rms.dao.LoginDao;
import com.bonc.rms.dao.UserDao;
import com.bonc.rms.service.LoginService;

@Service(value = "loginServiceImpl")
public class LoginServiceImpl implements LoginService {

    @Autowired
    UserDao userDao;
    @Autowired
    LoginDao loginDao;

	@Override
	public Map<String, Object> loginValidate(String userName, String password) {		
	    Map<String, Object> rsMap = new HashMap<String, Object>();
	    Integer userId = userDao.getUserIdByAccount(userName);
	    String passwd = userDao.getPasswordByAccount(userName);
	    String uName = userDao.getUserNameByAccount(userName);
	    
	    if(passwd == null || "".equals(passwd)){
	        rsMap.put("tag", 0); //用户不存在
	    }else{
	       if(password.equals(passwd)){
	           rsMap.put("tag", 1); //密码正确
	           rsMap.put("userId", userId);
	           rsMap.put("passwd", passwd);
	           rsMap.put("userName", uName);
	       }
	    }
	    
	    return rsMap;
	}

	@Override
	public Map<String, Object> mLogin(String userName, String password) {
		Map<String, Object> rsMap = new HashMap<String, Object>();
	    Integer userId = userDao.getManagerIdByAccount(userName);
	    String passwd = userDao.getManagerPwdByAccount(userName);
	    String uName = userDao.getManagerNameByAccount(userName);
	    
	    if(passwd == null || "".equals(passwd)){
	        rsMap.put("tag", 0); //用户不存在
	    }else{
	       if(password.equals(passwd)){
	           rsMap.put("tag", 1); //密码正确
	           rsMap.put("userId", userId);
	           rsMap.put("passwd", passwd);
	           rsMap.put("userName", uName);
	       }
	    }
	    
	    return rsMap;
	}


}
